package com.ninong.ker.admin.service.impl;

import java.util.Arrays;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ninong.ker.admin.domain.FwFormConfig;
import com.ninong.ker.admin.mapper.FwFormConfigMapper;
import com.ninong.ker.admin.service.FwFormConfigService;
import com.ninong.ker.admin.service.dto.FwFormConfigDTO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;



@Service
public class FwFormConfigServiceImpl extends ServiceImpl<FwFormConfigMapper, FwFormConfig> implements FwFormConfigService {

    @Override
	public PageInfo<FwFormConfig> listPage(FwFormConfigDTO dto) {
		PageHelper.startPage(dto.getCurrentPage(), dto.getPageSize());
		LambdaQueryWrapper<FwFormConfig> query = new LambdaQueryWrapper<>();
		if (StringUtils.isNotEmpty(dto.getName())){
			query.eq(FwFormConfig::getName,dto.getName());
		}
		List<FwFormConfig> FwFormConfigs = baseMapper.selectList(query);
		return new PageInfo<FwFormConfig>(FwFormConfigs);
	}

	@Override
	public void delete(String[] ids) {
		List<String> idList = Arrays.asList(ids);
		idList.forEach(id -> {		
			FwFormConfig entity = new FwFormConfig();
			entity.setId(id);
//			entity.setDeleted(false);
			baseMapper.updateById(entity);
		});
	}

	@Override
	public void create(FwFormConfig entity) {
		//校验自行实现
		saveOrUpdate(entity);
	}

	@Override
	public FwFormConfig get(String id) {
		FwFormConfig entity = baseMapper.selectById(id);
		if (ObjectUtils.isEmpty(entity)) {
			entity = new FwFormConfig();
		}
		return entity;
	}

}